package com.cwj.springboot_study.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cwj.springboot_study.mapper.DeptMapper;
import com.cwj.springboot_study.model.Dept;
import com.cwj.springboot_study.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author wujie.chen
 * 2022/10/24 11:07
 */
@Service
@Slf4j
public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements DeptService, IService<Dept> {
    @Override
    @Transactional
    public boolean saveDept(Dept dept) {
        if(this.baseMapper.exists(Wrappers.lambdaQuery(Dept.class).eq(Dept::getNo, dept.getNo()))){
            throw new RuntimeException("deptNo :" + dept.getNo() + "is exists");
        }
        dept.setDeleted(false);
        return this.save(dept);
    }
}
